package com.xcw.test;

import com.xcw.util.SmallTool;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

/**
 * @Author bhx
 * @Date 2022/7/19 1:49
 * @Description TODO
 */
public class MainTestCompletableFuture_2 {
    public static void main(String[] args) {
        SmallTool.printTimeAndThread("小白进入餐厅");
        SmallTool.printTimeAndThread("小白点餐：牛肉饭");
        CompletableFuture<String> completableFuture = CompletableFuture.supplyAsync(()->{
            SmallTool.printTimeAndThread("厨师炒菜");
            SmallTool.sleepMills(1000L);
            SmallTool.printTimeAndThread("厨师上盘");
            return "饭做好了！！";
        }).thenCompose(dish ->CompletableFuture.supplyAsync(()->{
            SmallTool.sleepMills(2000L);
            SmallTool.printTimeAndThread("服务员端盘！");
            SmallTool.printTimeAndThread("服务员完成服务！");
            return "服务员服务完成";
        }));
        CompletableFuture completableFuture1 = CompletableFuture.runAsync(() -> {
        }, new Executor() {
            @Override
            public void execute(Runnable command) {
                command.run();
            }
        });
        SmallTool.printTimeAndThread("小白付钱");
        SmallTool.printTimeAndThread(String.format("小白离开餐厅",completableFuture.join()));
    }
}
